import axios from 'axios';
import { getItem } from '@/utils/stroge'

// 创建第二个实例
const instance2 = axios.create({
    timeout: 5000,
    // baseURL: 'https://llm.yunzhangfang.com',
    baseURL: '/yunzhangfang'
});

// 实例2的请求拦截器
instance2.interceptors.request.use(
    config => {
        config.headers.token = getItem('chatToken')
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);
 
// 实例2的响应拦截器
instance2.interceptors.response.use(
    response => {
        return response;
    },
    error => {
        return Promise.reject(error)
    }
);

/**
 * 封装get方法
 * @param url
 * @param data
 * @returns {Promise}
 */
export function get2(url, params = {}) {
    return new Promise((resolve, reject) => {
        instance2.get(url, {
                params: params
            })
            .then(response => {
                resolve(response.data);
            })
            .catch(err => {
                reject(err)
            })
    })
}
 
/**
 * 封装post请求
 * @param url
 * @param data
 * @returns {Promise}
 */
export function post2(url, data = {}) {
    return new Promise((resolve, reject) => {
        instance2.post(url, data)
            .then(response => {
                resolve(response.data);
            }, err => {
                reject(err)
            })
    })
}